package com.example.plugin.action;

import com.example.plugin.ui.GenerateUI;
import com.intellij.database.psi.DbTable;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.ui.Messages;
import com.intellij.psi.PsiElement;

/**
 * GenarateAction
 *
 * @author lipan
 * @date 2022/1/16 9:36
 * @email 13160080997@163.com
 **/
public class GenarateAction extends AnAction {

    @Override
    public void actionPerformed(AnActionEvent e) {
        PsiElement[] psiElements = e.getData(LangDataKeys.PSI_ELEMENT_ARRAY);
        if (psiElements == null || psiElements.length != 1) {
            Messages.showMessageDialog("Please select only one or more tables", "Notice", Messages.getInformationIcon());
            return;
        }
        if(psiElements[0] instanceof DbTable){
            new GenerateUI(e);
        }
    }
}
